<template>
	<view class="index">
		<view class="item-wrapper">
			<view class="title-wrapper">
				<view class="title">
					配送信息
				</view>
			</view>
			<view class="form-wrapper">
				<view class="form-item">
					<view class="form-label require">
						电话号码
					</view>
					<view class="form-value">
						<input v-model="form.phone" maxlength="11" type="number" class="input" placeholder="请输入" />
					</view>
				</view>
				<view class="form-item">
					<view class="form-label">
						车牌号
					</view>
					<view class="form-value" @tap="plateShow = true">
						<text v-if="plateNo">{{ plateNo }}</text>
						<text v-else class="placeholder">请输入</text>
					</view>
				</view>
				<view class="form-item">
					<view class="form-label">
						备注
					</view>
					<view class="form-value">
						<textarea v-model="form.remark" class="textarea" placeholder="请输入"></textarea>
					</view>
				</view>
			</view>
		</view>
		<view class="btn-wrapper">
			<view class="btn" @click="submit">
				提交
			</view>
		</view>
		<plate-input v-if="plateShow" :plate="plateNo" @export="setPlate" @close="plateShow = false" />
	</view>
</template>

<script>
	import plateInput from '@/components/uni-plate-input/uni-plate-input.vue';
	export default {
		data() {
			return {
				plateShow: false,
				plateNo: '',
				form: {
					id: '',
					phone: '',
					remark: '',
					vehicleNo: ''
				}
			}
		},
		onLoad(option) {
			this.form.id = option.id;
			if (option.params) {
				const params = JSON.parse(option.params);
				this.form.phone = params.phone;
				this.form.remark = params.remark;
				this.form.vehicleNo = params.vehicleNo;
				this.plateNo = params.vehicleNo;
			}
		},
		methods: {
			setPlate(plate) {
				if (plate.length >= 7) this.plateNo = plate;
				this.plateShow = false;
				this.form.vehicleNo = plate;
			},
			async submit() {
				if (!this.form.phone) {
					uni.showToast({
						title: '请输入电话号码',
						icon: 'none'
					})
					return;
				}
				const data = await this.$api.post('/app/deliver/order/switchToDelivery', this.form)
				if (data.code === 200) {
					uni.showToast({
						title: '操作成功'
					})
					const pages = getCurrentPages();
					if (pages.length > 1) {
						const beforePage = pages[pages.length - 2];
						if (beforePage.route === 'subPage_pickup/index') {
							beforePage.$vm.search();
						} else {
							beforePage.$vm.getInfo(this.form.id);
						}
					}
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				}
			}
		},
		components: {
			plateInput
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		.item-wrapper {
			background-color: #ffffff;
			margin: 20upx 20upx 0 20upx;
			border-radius: 20upx;
			padding: 25upx;

			&.error {
				box-shadow: 0 0 7upx red;
			}

			.title-wrapper {
				display: flex;
				align-items: center;
				margin-bottom: 40rpx;

				.icon {
					margin-right: 5upx;
				}

				.title {
					height: 34upx;
					line-height: 34upx;
					font-size: 34upx;
					color: #222222;
					padding-left: 10upx;
					border-left: 8upx solid #F26022;
				}

				.value {
					flex: 1;
					text-align: right;
					font-size: 32upx;
					color: #333333;

					&.black {
						color: #222222;
					}
				}

				.input {
					flex: 1;
					text-align: right;
					font-size: 32upx;
					color: #333333;
					margin-right: 10upx;
				}
			}

			.input-wrapper {
				padding-top: 15upx;

				.input {
					font-size: 32upx;
					padding: 10upx;
					height: 60upx;
				}

				.text-area {
					width: 100%;
					font-size: 32upx;
					height: 60upx;
					padding: 10upx;
				}
			}

			.tip {
				font-size: 26upx;
				color: #898989;
			}

			.form-wrapper {
				padding: 0 20upx;

				.form-item {
					display: flex;
					justify-content: space-between;
					font-size: 32upx;
					margin-top: 20upx;
					min-height: 50rpx;
					line-height: 50rpx;
					border-bottom: 1upx dashed #cecece;
					padding-bottom: 20rpx;

					&:last-child {
						border-bottom: 0;
					}

					.form-label {
						width: 150upx;
						color: #232323;

						&.require::after {
							content: '*';
							color: red;
						}
					}

					.form-value {
						flex: 1;
						color: #333333;
						display: flex;
						align-items: center;

						.placeholder {
							color: #777777;
						}

						.input {
							font-size: 32rpx;
						}

						.textarea {
							width: 100%;
							font-size: 32rpx;
							height: 120rpx;
						}
					}
				}
			}
		}

		.btn-wrapper {
			margin-top: 100rpx;
			padding: 0 20rpx;
			height: 100upx;
			width: 100%;
			display: flex;
			align-items: center;
			z-index: 1;
			box-sizing: border-box;


			.btn {
				border-radius: 10rpx;
				overflow: hidden;
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 2;
				height: 100%;
				background-color: #F26022;
				color: #ffffff;

				&.default {
					flex: 1;
					margin-right: 20rpx;
					color: #232323;
					background-color: #ffffff;
					border: 1upx solid #cecece;
				}
			}
		}

	}
</style>